var fs = require("fs");
var data = '';
var count = 0;
//create a readable stream
var readerStream = fs.createReadStream('test.txt');
console.log("readerStream",readerStream)
//set the encoding to be utf8. 
readerStream.setEncoding('UTF8');

//handle stream events
readerStream.on('data', function(chunk) {
    console.log(`data ${++count}`, chunk);
   data += chunk;
});

readerStream.on('end',function(){
   console.log("end",data);
});

readerStream.on('error', function(err){
   console.log(err.stack);
});
console.log("Program Ended");

console.log(count);

